﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkitApp.Models;
using CommunityToolkitApp.Services;

namespace CommunityToolkitApp.ViewModels
{
    public partial class MainWindowViewModel : ObservableObject
    {
        public ITestService TestService { get; set; }

        [ObservableProperty]
        private string title = "Hello,World";

        [ObservableProperty]
        [NotifyCanExecuteChangedFor(nameof(ButtonClickCommand))]
        private bool isEnabled = true;

        public MainWindowViewModel()
        {
            this.TestService = Ioc.Default.GetRequiredService<ITestService>();
        }

        [RelayCommand(CanExecute = nameof(CanButtonClick))]
        private void ButtonClick()
        {
            this.Title = "Hello,World On WPF";

            var messageObject = new MessageObject<string>("dddfdsa");
            WeakReferenceMessenger.Default.Send(messageObject);
        }

        private bool CanButtonClick() => IsEnabled;
    }
}
